package container.lis;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TestArrayList
{
    public static void main (String[] args)
    {
//        ArrayList arrayList1 = new ArrayList<>();           //方法最丰富，更换容器麻烦，会影响后期维修
        List<String> arrayList2 = new ArrayList<String>();    //方法较少，未来更换容器更简单，代码修改简单，如果容器不用ArrayList独有方法则更建议使用这个
//        Collection arryaList3 = new ArrayList<>();          //方法最少，一般不用
    
        boolean flag1 = arrayList2.add("Old lu");
        boolean flag2 = arrayList2.add("123");
        boolean flag3 = arrayList2.add("123");
    
        System.out.println(flag1 + "\t" + flag2 + "\t" + flag3);
    
        String old = (arrayList2.remove(2));
        System.out.println(old);
        
        //将ArrayList转化为数组
        Object[] objects = arrayList2.toArray(new String[0]);
        System.out.println(Arrays.toString(objects));
        
        int longth = arrayList2.size();
        System.out.println(longth);
        
        String k = arrayList2.set(1,"654");    //返回被替换的元素
        System.out.println(k);
        
        String j = arrayList2.remove(1); //返回被删除的元素
        System.out.println(j);
        
        arrayList2.add("ilu");
        arrayList2.add("arraylist");
        
        System.out.println(arrayList2.get(1));
        
        boolean isEmpty = arrayList2.isEmpty();
        System.out.println(isEmpty);
        
        boolean ishave = arrayList2.contains("123");
        System.out.println(ishave);
        
        arrayList2.clear();
        Object[] objects1 = arrayList2.toArray(new String[0]);
        System.out.println(Arrays.toString(objects1));
    }
}
